/*-+-*****************************************************************************
 Copyright (C) 2009-2012 Oceanside Software Corporation (R)
 Dallas, Texas

 Author       : Jason T. Brower
 Purpose      : This file is part of a point-of-sale software package
                originally written for Table-Service Restaurants.
              
 Date         : July 8th of 2012
              
 History      : The application that this software file belongs to was 
                written over a 3-Year period.  The first version was written
                in C# .Net 3.5 using Windows Forms.  Being new to .Net at
                the time, I soon learned of Windows Presentation Foundation,
                liked the graphics capabilities and databinding so I
                migrated to WPF.  When the .Net 4.0 framework was released
                the application was migrated from 3.5 to 4.0. Now today,
                .Net 4.5 RC is out and I was already in process of migrating
                before I made this public.
                
Excuse Me     : Please excuse the coding style, it is not representative of
                my typical work.  During the three years I was under a very
                tight budget, constantly running out of funding and was 
                working 18 hour days hyped up on 5-Hour Energy.  The 
                design is not textbook.  It is monolythic because of
                previous issues I will not get into.  There are few comments
                in the code and the ones that are there may be incorrect.
                
What it is not: This is not the exact version that I took through PA-DSS 2.0
                nor is it the exact version running at my customer sites.
                I removed some details for security purposes including some
                encryption algorithms.  The reporting was removed because
                I was including a third party library that cannot be 
                published with this Open Source.
                
What it is    : This application has been running at high volume restaraunts
                for over a year.  It never freezes, crashes or does anything
                unexpected.  So long as it is built, installed and configured
                correctly, it is a strong system that we can all enhance.

Contact       : Please note that I can no longer work for free.  However, you
                can reach me at information@oceansidesw.com.                                                      

*********************************************************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
namespace Oceanside.Payments
{
    public class LoyaltyResponse2
    {
        public CmdResponse CommandResponse = new CmdResponse();
        public string MerchantID;
        public string TerminalID;
        public string AcctNo;
        public string ExpDate;
        public string CardType;
        public string TranCode;
        public string AuthCode;
        public string CaptureStatus;
        public string RefNo;
        public string InvoiceNo;
        public string OperatorID;
        public string Format;
        public string Memo;
        public string Purchase;
        public string Authorize;
        public string LoyaltyExp;
        public string PointsBalance;
        public string UnitsBalance;
        public string PriceBalance;
        public string PointsBalance2;
        public string UnitsBalance2;
        public string PriceBalance2;
        public string PointsBalance3;
        public string UnitsBalance3;
        public string PriceBalance3;
        public string PointsBalance4;
        public string UnitsBalance4;
        public string PriceBalance4;
        public string PointsBalance5;
        public string UnitsBalance5;
        public string PriceBalance5;
        public string PointsBalance6;
        public string UnitsBalance6;
        public string PriceBalance6;
        public string PointsBalance7;
        public string UnitsBalance7;
        public string PriceBalance7;
        public string PointsBalance8;
        public string UnitsBalance8;
        public string PriceBalance8;
        public string TotalPointsBalance;
        public string TotalUnitsBalance;
        public string TotalPriceBalance;
        public string WriteReceipt;

        public bool Parse(string inResponse)
        {
            bool success = false;
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.LoadXml(inResponse);
                CommandResponse.ResponseOrigin =
                    PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("ResponseOrigin"));
                CommandResponse.DSIXReturnCode =
                    PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("DSIXReturnCode"));
                CommandResponse.CmdStatus =
                    PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("CmdStatus"));
                CommandResponse.TextResponse =
                    PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("TextResponse"));
                CommandResponse.SequenceNo =
                    PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("SequenceNo"));
                CommandResponse.UserTraceData =
                    PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("UserTraceData"));


                MerchantID = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("MerchantID"));
                TerminalID = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("TerminalID"));
                AcctNo = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("AcctNo"));
                ExpDate = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("ExpDate"));
                CardType = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("CardType"));
                TranCode = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("TranCode"));
                AuthCode = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("AuthCode"));
                CaptureStatus = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("CaptureStatus"));
                RefNo = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("RefNo"));
                InvoiceNo = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("InvoiceNo"));
                OperatorID = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("OperatorID"));
                Format = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("Format"));
                Memo = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("Memo"));
                Purchase = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("Purchase"));
                Authorize = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("Authorize"));
                LoyaltyExp = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("LoyaltyExp"));
                PointsBalance = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PointsBalance"));
                UnitsBalance = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("UnitsBalance"));
                PriceBalance = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PriceBalance"));
                PointsBalance2 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PointsBalance2"));
                UnitsBalance2 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("UnitsBalance2"));
                PriceBalance2 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PriceBalance2"));
                PointsBalance3 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PointsBalance3"));
                UnitsBalance3 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("UnitsBalance3"));
                PriceBalance3 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PriceBalance3"));
                PointsBalance4 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PointsBalance4"));
                UnitsBalance4 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("UnitsBalance4"));
                PriceBalance4 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PriceBalance4"));
                PointsBalance5 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PointsBalance5"));
                UnitsBalance5 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("UnitsBalance5"));
                PriceBalance5 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PriceBalance5"));
                PointsBalance6 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PointsBalance6"));
                UnitsBalance6 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("UnitsBalance6"));
                PriceBalance6 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PriceBalance6"));
                PointsBalance7 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PointsBalance7"));
                UnitsBalance7 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("UnitsBalance7"));
                PriceBalance7 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PriceBalance7"));
                PointsBalance8 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PointsBalance8"));
                UnitsBalance8 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("UnitsBalance8"));
                PriceBalance8 = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("PriceBalance8"));
                TotalUnitsBalance = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("TotalPointsBalance"));
                TotalUnitsBalance = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("TotalUnitsBalance"));
                TotalPriceBalance = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("TotalPriceBalance"));
                WriteReceipt = PaymentEngine.NullCheckGetText(doc.GetElementsByTagName("WriteReceipt"));

                success = true;
            }
            catch (Exception e)
            {
                Logging.LogException(e);
            }
            return success;
        }
    }
}
